package com.sevencar.activity;


import com.example.lightble.R;

import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.TextView;

public class LightGroupAddItem  extends LinearLayout{

	private Activity mActivity;
	private TextView  mDevName;
	private CheckBox  mCkbox;
//	private BluetoothDevice mDevice;
	
	private String name;
	private String address;
	
	
	
	private onChecedChangeListener  mOnChecedChangeListener;
	public interface onChecedChangeListener {
		void onCheckedChanged(LightGroupAddItem view,String address,boolean isChecked);  
	}
	public void setOnChecedChangeListener(onChecedChangeListener callback) {
		mOnChecedChangeListener = callback;
	}
	
	   public LightGroupAddItem(Activity acty,BluetoothDevice device) {
	        super(acty);
	        mActivity=acty;
//	        mDevice=device;
	        
	        name = device.getName();
	        address = device.getAddress();
	        
	        LayoutInflater inflater=(LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        inflater.inflate(R.layout.light_group_add_item,this);
	       
	        mDevName=(TextView)findViewById(R.id.id_light_group_add_item_tv);
	        mCkbox=(CheckBox)findViewById(R.id.id_light_group_add_item_checkbox);
	        
	        mCkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
					if(mOnChecedChangeListener!=null)
						mOnChecedChangeListener.onCheckedChanged(LightGroupAddItem.this, address,isChecked);
				}
			});
	        mDevName.setText(name);
	   }
	   public LightGroupAddItem(Activity acty,String _name ,String _address) {
		   super(acty);
		   mActivity=acty;
//		   mDevice=device;
		   
		   name = _name;
		   address = _address;
		   
		   LayoutInflater inflater=(LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		   inflater.inflate(R.layout.light_group_add_item,this);
		   
		   mDevName=(TextView)findViewById(R.id.id_light_group_add_item_tv);
		   mCkbox=(CheckBox)findViewById(R.id.id_light_group_add_item_checkbox);
		   mCkbox.setChecked(true);
		   
		   mCkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			   
			   @Override
			   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				   if(mOnChecedChangeListener!=null)
					   mOnChecedChangeListener.onCheckedChanged(LightGroupAddItem.this, address,isChecked);
			   }
		   });
		   mDevName.setText(address);
	   }
	   public boolean isChecked()
	   {
		   return  mCkbox.isChecked();
	   }
	   public String getDeviceAddress()
	   {
		   return address;
	   }
	   public String getDeviceName()
	   {
		   return name;
	   }
}
